package com.gy.niuer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gy.niuer.domain.Clinic;
import com.gy.niuer.domain.Doctor;
import com.gy.niuer.domain.Scheduling;
import com.gy.niuer.service.SchedulingService;
import com.gy.niuer.mapper.SchedulingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
*
*/
@Service
public class SchedulingServiceImpl extends ServiceImpl<SchedulingMapper, Scheduling>
implements SchedulingService{


    @Autowired
    SchedulingMapper schedulingMapper;

    @Override
    public boolean updateCount(int scheduling) {
        Scheduling scheduling1 = schedulingMapper.selectOneById(scheduling);
        int i = scheduling1.getCount();

        if(i == 30){
            return true;
        }else{
            schedulingMapper.updateCountById(i + 1,scheduling);
            return false;
        }
    }

    @Override
    public boolean deleteScheduling(int doctorId, Date time) {

        int count = schedulingMapper.selectCountByDoctorAndTime(doctorId, time);

        if(count == 0){
            schedulingMapper.deleteByDoctorAndTime(doctorId, time);
            return true;
        }

        return false;

    }

    @Override
    public List<Scheduling> selectSchedulingByDoctor(int doctor) {
        List<Scheduling> schedulings = schedulingMapper.selectAllByDoctor(doctor);
        return schedulings;
    }
}
